package com.vg.Adapter;

import java.util.ArrayList;

import com.vg.classSample.ItemStudent;
import com.vg.classSample.Student;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MyAdapter extends ArrayAdapter<Student>{
	private Context mContext;
	private ArrayList<Student> arrayList;
	private boolean isCancel;

	public MyAdapter(Context context, int textViewResourceId,ArrayList<Student> array, boolean cancel) {
		super(context, textViewResourceId, array);
		// inital: khoi tao
		this.mContext = context;
		this.arrayList = array;
		this.isCancel = cancel;
	}
	
	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		//return super.getDropDownView(position, convertView, parent);
		return getViewdrop(position, convertView, parent);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		//return super.getView(position, convertView, parent);
		return getViewdrop(position, convertView, parent);
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	@Override
	public Student getItem(int position) {	
		// TODO Auto-generated method stub
		return super.getItem(position);
	}
	
public View getViewdrop(int position, View convertView, ViewGroup parent) {
	View view = convertView;
	if(view==null){
		view = new ItemStudent(mContext);
	}
	// lay phan tu mang thu position
	final Student student = arrayList.get(position);
	if(student!=null){
		TextView name = ((ItemStudent)view).name;		
		name.setText(student.getName());
	}

	return view;
}
}
